﻿using System;
using System.IO;
using System.Text;

namespace Program07
{
    class Program
    {
        static void Main(string[] args)
        {
            //使用FileStream来写入文件
            //using(FileStream fsWrite = new FileStream("new.txt",FileMode.OpenOrCreate,FileAccess.Write))
            //{
            //    var str = "规范的风景";
            //    //把字符串转成二进制
            //    byte[] buffer = Encoding.UTF8.GetBytes(str);
            //    fsWrite.Write(buffer, 0, buffer.Length);
            //}

            //读取文件
            FileStream fsRead = new FileStream(@"D:\软件工程项目管理\CsharpAdvanced\Program07\bin\Debug\netcoreapp3.1\new.txt", FileMode.OpenOrCreate, FileAccess.Read);
            //读取文件不超过5m大小
            byte[] buffer = new byte[1024 * 10248 * 5];
            //读取当前文件有效字符
            int r = fsRead.Read(buffer, 0, buffer.Length);
            //将读出的二进制转换成UTF-8格式字符串
            string str  = Encoding.UTF8.GetString(buffer,0,r);
            //关闭文件流
            fsRead.Close();
            //释放储存空间线程
            fsRead.Dispose();
            Console.WriteLine(str);

        }
    }
}
